home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 2
/
Nebula Two.iso
/
SourceCode
/
AlexNeXTSTEPSource
/
Source
/
Chapter8_Prefs
/
Money
/
MoneyConverter.m
< prev
next >
Wrap
Text File
|
1995-06-12
|
1KB
|
64 lines
/* Generated by Project Builder */
#import <appkit/appkit.h>
#import "MoneyConverter.h"
#import "PrefsController.h"
#define MAXIMUM 6
@implementation MoneyConverter
- convert:sender
{
int index, loop;
unsigned int right,left = 10;
float entry, value, dollar_equiv;
id cell;
// Array contains the conversion of rates
// of other currencies to dollars
static float rate[MAXIMUM] =
{1.00, 135.0, 0.50, 1.67, 6.00, 14.5};
// Determine which field of the form
// was the last to be edited
index = [moneyForm selectedIndex];
// Calculate equivalent of foreign currency
// at edited field to dollar equivalent
entry = [moneyForm floatValueAt:index];
dollar_equiv = entry / rate[index];
// check if the Truncate default is set
// and then set the number of figures
// to the right of the decimal point
if ([prefsController shouldTruncate] == YES)
right = 2;
else
right = 6;
// set floating point format for each
// formcell in the form
for (loop=0; loop < MAXIMUM; loop++)
{
// get each cell
cell = [moneyForm cellAt:loop :0];
[cell setFloatingPointFormat:NO
left:left right:right];
}
for (loop = 0; loop < MAXIMUM; loop++)
{
// Calculate other currencies
// using look-up table
value = dollar_equiv * rate[loop];
// display value at appropriate field
[moneyForm setFloatValue:value at:loop];
}
// leave the last edited field as the
// selected text
[moneyForm selectTextAt:index];
return self;
}
@end